'use strict';
// npx sequelize migration:generate --name=<操作名称></操作名称>
// npx sequelize db:migrate
// npx sequelize db:migrate:undo

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const { INTEGER, DATE, STRING, BOOLEAN, DECIMAL } = Sequelize;
    await queryInterface.createTable('books', {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      title: STRING(255),
      code: { type: STRING(30), unique: true },
      description: STRING(200),
      status: BOOLEAN,
      created_at: DATE,
      updated_at: DATE,
    });

    await queryInterface.createTable('corps', {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      title: STRING(255),
      code: { type: STRING(30), unique: true },
      hscode: { type: STRING(30), unique: true },
      description: STRING(200),
      status: BOOLEAN,
      created_at: DATE,
      updated_at: DATE,
    });

    await queryInterface.createTable('goods', {
      id: { type: INTEGER, primaryKey: true, autoIncrement: true },
      sku: { type: STRING(255), comment: '商品SKU', unique: true },
      materialsCode: { type: STRING(255), comment: '商品料件号' },
      hscode: { type: STRING(30), comment: '商品海关编码' },
      title: { type: STRING(30), comment: '商品名称' },
      model: { type: STRING(255), comment: '商品型号' },
      goodsIdUnit: { type: STRING(10), comment: '商品料件号对应计量单位' },
      skuUnit: { type: STRING(10), comment: '商品SKU对应计量单位' },
      ratio: { type: STRING(10), comment: '商品SKU对应商品料件号数量换算比例' },
      unit1: { type: STRING(10), comment: '法定单位' },
      unit2: { type: STRING(10), comment: '第二单位' },
      description: STRING(200),
      status: BOOLEAN,
      created_at: DATE,
      updated_at: DATE,
    });
  },

  down: async queryInterface => {
    await queryInterface.dropTable('books');
    await queryInterface.dropTable('corps');
    await queryInterface.dropTable('goods');
  },
};
